package br.org.credfaz.sis.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import br.org.credfaz.sis.MysqlConnectionFactory;
import br.org.credfaz.sis.modelo.ContratoCredito;


public class ContratoCreditoDAO {
	
private final Connection connection;
	
	public ContratoCreditoDAO(){
		try{
			connection = new MysqlConnectionFactory().getConnection();
		}catch (SQLException e){
			throw new RuntimeException(e);
		}
	}
	
	public void adiciona(ContratoCredito contratocredito){
		String sql = "insert into contratocredito (idmodalidadeproduto, idcliente, numcontratocredito, idindicadorcalculo," +
				"codtiposituacaotitulo, dataoperacao, datavencopcred, dataclassificacaorisco, idnivelrisco, perctaxajuros, perctaxamora, perctaxamulta, valorcontratoopcred," +
				"valoriof, valorsaldodevedorcontabil, datahoracarga) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
		PreparedStatement stmt;
		try{
			stmt = connection.prepareStatement(sql);
			
			stmt.setLong(1, contratocredito.getIdmodalidadeproduto());
			stmt.setFloat(2, contratocredito.getIdcliente());
			stmt.setFloat(3, contratocredito.getNumcontratocredito());
			stmt.setInt(4, contratocredito.getIdindicadorcalculo());
			stmt.setLong(5, contratocredito.getCodtiposituacaotitulo());
			stmt.setDate(6, contratocredito.getDataoperacao());
			stmt.setDate(7, contratocredito.getDatavencopcred());
			stmt.setDate(8, contratocredito.getDataclassificacaorisco());
			stmt.setString(9, contratocredito.getIdnivelrisco());
			stmt.setFloat(10, contratocredito.getPerctaxajuros());
			stmt.setFloat(11, contratocredito.getPerctaxamora());
			stmt.setFloat(12, contratocredito.getPerctaxamulta());
			stmt.setDouble(13, contratocredito.getValorcontratoopcred());
			stmt.setFloat(14, contratocredito.getValoriof());
			stmt.setDouble(15, contratocredito.getValorsaldodevedorcontabil());
			stmt.setDate(16, contratocredito.getDatahoracarga());
			
			stmt.execute();
			
		}catch (SQLException e){
			throw new RuntimeException(e);
		}
	}

}
